package com.tckdq.tcc.service.impl;

import com.tckdq.tcc.domain.Login;
import com.tckdq.tcc.mapper.LoginMapper;
import com.tckdq.tcc.result.JsonResult;
import com.tckdq.tcc.service.ILoginService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 登录表 服务实现类
 * </p>
 *
 * @author whale
 * @since 2022-08-12
 */
@Service
public class LoginServiceImpl extends ServiceImpl<LoginMapper, Login> implements ILoginService {


    @Autowired
    private LoginMapper loginMapper;

    //注册
    @Override
    public Long save(Login login) {
        insert(login);
        return login.getId();
    }

    //登录
    @Override
    public JsonResult login(Login login) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",login.getType());
        map.put("username",login.getUsername());
        map.put("password",login.getPassword());
        List<Login> logins = loginMapper.selectByMap(map);
        for (Login login1 : logins) {
            if (!StringUtils.isEmpty(login1)){
                return JsonResult.success(login1);
            }
        }
        return JsonResult.error("您的账号没有注册");
    }
}
